<?php
/**
 * @author 
 * @copyright 2014
 */
 
 
class PhongbanModel extends CI_Model
{
    var $_menus = array();
    
	function __construct(){
		parent::__construct('department');
	}
	function save($data,$id){
		$this->db->trans_start();
		$data['types'] = 1;
		if(empty($id)){
			$data['datecreate'] =  gmdate("Y-m-d H:s:i", time() + 7 * 3600);
			$data['usercreate'] = $this->pub->login['username']; 	
			$this->model->insert($data);
		}
		else{
			$data['dateupdate'] =  gmdate("Y-m-d H:s:i", time() + 7 * 3600);
			$data['userudate'] = $this->pub->login['username']; 	
			$this->model->where('id',$id)->update($data);
		}
		$this->db->trans_complete();
		if ($this->db->trans_status() === FALSE){
			return 0;
		}
		else{
			return 1;	
		}
	}
	function delete($str,$item){
		if(!empty($item)){
			$this->model->where('id',$item)->update(array('isdelete'=>1));
			echo 1;
		}
		else{
			$array = explode(',',$str);
			foreach($array as $k=>$id){
				$this->model->where('id',$id)->update(array('isdelete'=>1));	
				echo 1;
			}
		}
	}
}